package com.tmall.testgen.server.infocollect;

import java.io.OutputStream;
import java.util.ArrayList;

import com.tmall.testgen.common.bo.BaseUserCenter;
import com.tmall.testgen.common.bo.interact.back.InterceptInfo;
import com.tmall.testgen.common.bo.interact.back.LoadedClassAndMethod;
import com.tmall.testgen.common.bo.interact.back.TransferCarFromServer;
import com.tmall.testgen.common.bo.interact.back.syn.BaseInfo;
import com.tmall.testgen.common.socket.TransferHandler;
import com.tmall.testgen.common.util.InterceptorConvertor;

/**
 * @author haojia
 * @date 2014-07-04
 */
public class UserData extends BaseUserCenter{
	
	
	

	/**
	 * 
	 */
	private OutputStream outPutStream;
	
	
	public OutputStream getOutPutStream() {
		return outPutStream;
	}
	public void setOutPutStream(OutputStream outPutStream) {
		this.outPutStream = outPutStream;
	}
	
	public void addLoadedInterceptClassAndMethods(String className,String method){
		super.addLoadedInterceptClassAndMethods(className, method);
		
		LoadedClassAndMethod la=new LoadedClassAndMethod();
		la.setClassName(className);
		la.setMethod(method);
		la.setType(BaseInfo.TYPE_INTERCEPT);
		
		this.writeObject(new TransferCarFromServer(TransferCarFromServer.TYPE_LOADED_CLASS_AND_METHOD, la));
	}
	
	public void addLoadedMockClassAndMethods(String className,String method){
		super.addLoadedMockClassAndMethods(className, method);
		
		LoadedClassAndMethod la=new LoadedClassAndMethod();
		la.setClassName(className);
		la.setMethod(method);
		la.setType(BaseInfo.TYPE_MOCK);
		
		this.writeObject(new TransferCarFromServer(TransferCarFromServer.TYPE_LOADED_CLASS_AND_METHOD, la));
	}
	
	public void addUserInfo(InterceptInfo info){
	    //System.out.println("isStart"+start);
		if(!start)
			return;
		
		super.addInterceptInfo(info);
		writeObject( new TransferCarFromServer(TransferCarFromServer.TYPE_INTERCEPT_INFO,  InterceptorConvertor.interceptInfo2TransferInterceptInfo(info)));
		
	}
	
	
	
	public  void writeObject(Object obj){
		try {
			TransferHandler.writeObject(outPutStream, obj);
		} catch (Exception e) {
			e.printStackTrace();
		}
       
	}
	
	
}
